package cn.px.sa.admin.module.sygl.gwatertypemanager.service;

import java.util.List;

import cn.px.sa.admin.module.sygl.gwatertypemanager.dao.GWaterTypeManagerDao;
import cn.px.sa.admin.module.sygl.gwatertypemanager.domain.entity.GWaterTypeManagerEntity;
import cn.px.sa.admin.module.sygl.gwatertypemanager.domain.form.GWaterTypeManagerAddForm;
import cn.px.sa.admin.module.sygl.gwatertypemanager.domain.form.GWaterTypeManagerQueryForm;
import cn.px.sa.admin.module.sygl.gwatertypemanager.domain.form.GWaterTypeManagerUpdateForm;
import cn.px.sa.admin.module.sygl.gwatertypemanager.domain.vo.GWaterTypeManagerVO;
import cn.px.sa.base.common.util.SmartBeanUtil;
import cn.px.sa.base.common.util.SmartPageUtil;
import cn.px.sa.base.common.domain.ResponseDTO;
import cn.px.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用水类型管理 Service
 *
 * @author 品讯科技
 * @date 2024-08
 * @Copyright 1
 */

@Service
public class GWaterTypeManagerService {

    @Resource
    private GWaterTypeManagerDao gWaterTypeManagerDao;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<GWaterTypeManagerVO> queryPage(GWaterTypeManagerQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<GWaterTypeManagerVO> list = gWaterTypeManagerDao.queryPage(page, queryForm);
        PageResult<GWaterTypeManagerVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(GWaterTypeManagerAddForm addForm) {
        GWaterTypeManagerEntity gWaterTypeManagerEntity = SmartBeanUtil.copy(addForm, GWaterTypeManagerEntity.class);

        gWaterTypeManagerDao.insert(gWaterTypeManagerEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     * @param updateForm
     * @return
     */
    public ResponseDTO<String> update(GWaterTypeManagerUpdateForm updateForm) {
        GWaterTypeManagerEntity gWaterTypeManagerEntity = SmartBeanUtil.copy(updateForm, GWaterTypeManagerEntity.class);
        gWaterTypeManagerDao.updateById(gWaterTypeManagerEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        gWaterTypeManagerDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        gWaterTypeManagerDao.deleteById(id);
        return ResponseDTO.ok();
    }
}
